from peewee import *

db = MySQLDatabase('test',
                   **{'charset': 'utf8', 'sql_mode': 'PIPES_AS_CONCAT', 'use_unicode': True, 'user': 'root',
                      'password': 'root'})


class UnknownField(object):
    def __init__(self, *_, **__): pass


class BaseModel(Model):
    class Meta:
        database = db


class User(BaseModel):
    age = IntegerField(null=True)
    birthday = DateTimeField(null=True)
    name = CharField(null=True)

    class Meta:
        table_name = 'user'


# 批量插入对象
from random import randint

users = [
    User(name=f'田七{i}号', age=randint(20, 40), birthday=f'{randint(1980, 2010)}-{randint(1, 13)}-{randint(1, 29)}')
    for i in range(10000)
]

with db.atomic():
    User.bulk_create(users, batch_size=100)
